package bairui.international.model.status;

/**
 *
 * (产品订单状态)State_ProductOrder
 */
@com.lianjing.sh.processing.info.annotation.GenerateInfoModel
@com.lianjing.sh.model.common.annotation.Comment("产品订单状态")
@com.lianjing.sh.processing.info.annotation.InfoComment("产品订单状态")
public enum State_ProductOrder implements com.sh_lianjing.state.Statable, com.sh_lianjing.standard.EnumCommentable<State_ProductOrder> {

	/**
	 * <b>状态:</b> </br>
	 * (审核不通过)VerifyNoPass</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("审核不通过")
	@com.lianjing.sh.processing.info.annotation.InfoComment("审核不通过")
	VerifyNoPass("审核不通过")
,
	/**
	 * <b>状态:</b> </br>
	 * (已发货)Sended</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("已发货")
	@com.lianjing.sh.processing.info.annotation.InfoComment("已发货")
	Sended("已发货")
,
	/**
	 * <b>状态:</b> </br>
	 * (已终止)Terminaled</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("已终止")
	@com.lianjing.sh.processing.info.annotation.InfoComment("已终止")
	Terminaled("已终止")
,
	/**
	 * <b>状态:</b> </br>
	 * (待审核)Verifing</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("待审核")
	@com.lianjing.sh.processing.info.annotation.InfoComment("待审核")
	Verifing("待审核")
,
	/**
	 * <b>状态:</b> </br>
	 * (已取消)Canceled</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("已取消")
	@com.lianjing.sh.processing.info.annotation.InfoComment("已取消")
	Canceled("已取消")
,
	/**
	 * <b>状态:</b> </br>
	 * (待发货)Sending</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("待发货")
	@com.lianjing.sh.processing.info.annotation.InfoComment("待发货")
	Sending("待发货")
,
	/**
	 * <b>状态:</b> </br>
	 * (完成)Finished</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("完成")
	@com.lianjing.sh.processing.info.annotation.InfoComment("完成")
	Finished("完成")
,
	/**
	 * <b>状态:</b> </br>
	 * (待付款)Paying</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("待付款")
	@com.lianjing.sh.processing.info.annotation.InfoComment("待付款")
	Paying("待付款")
;

	private static java.util.Map<String, State_ProductOrder> Cache = new java.util.HashMap<>();
	static{
		for(State_ProductOrder enumItem : State_ProductOrder.values()){
			Cache.put(enumItem.getComment(), enumItem);
		}
	}

	private String comment;

	private State_ProductOrder(String comment){
		this.comment = comment;
	}

	@Override
	public String toString() {
		return comment;
	}

	@Override
	public String getComment() {
		return comment;
	}

	/**
	 * 通过备注解析状态相关
	 */
	@Override
	public State_ProductOrder parseByComment(String comment) {
		return State_ProductOrder.parse(comment);
	}

	public static State_ProductOrder parse(String comment) {
		State_ProductOrder enumItem = Cache.get(comment);
		if(null == enumItem){
			 throw new com.sh_lianjing.standard.exception.EnumCommentableException(State_ProductOrder.class, comment);
		}
		return enumItem;
	}

	/**
	 * from 转换方法相关
	 */
	/** <b>发货(待发货状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_send_from_Sending() throws com.sh_lianjing.state.StateConvertException {
		if(this != Sending){
			throw new com.sh_lianjing.state.StateConvertException(this, Sended);
		}
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("发货", this, Sended);
	}

	/** <b>审核(待审核状态)不通过</b> */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_verifyNoPass_from_Verifing() throws com.sh_lianjing.state.StateConvertException {
		if(this != Verifing){
			throw new com.sh_lianjing.state.StateConvertException(this, VerifyNoPass);
		}
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("审核不通过", this, VerifyNoPass);
	}

	/** <b>审核(待审核状态)通过</b> */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_verifyPass_from_Verifing() throws com.sh_lianjing.state.StateConvertException {
		if(this != Verifing){
			throw new com.sh_lianjing.state.StateConvertException(this, Finished);
		}
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("审核通过", this, Finished);
	}

	/** <b>支付(待付款状态)产品订单</b> */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_payProduct_from_Paying() throws com.sh_lianjing.state.StateConvertException {
		if(this != Paying){
			throw new com.sh_lianjing.state.StateConvertException(this, Sending);
		}
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("支付产品订单", this, Sending);
	}

	/** <b>支付(待付款状态)积分订单</b> */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_payGrade_from_Paying() throws com.sh_lianjing.state.StateConvertException {
		if(this != Paying){
			throw new com.sh_lianjing.state.StateConvertException(this, Verifing);
		}
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("支付积分订单", this, Verifing);
	}

	/** <b>处理(已发货状态)货到付款</b> */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_dealGoods_from_Sended() throws com.sh_lianjing.state.StateConvertException {
		if(this != Sended){
			throw new com.sh_lianjing.state.StateConvertException(this, Verifing);
		}
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("处理货到付款", this, Verifing);
	}

	/** <b>处理(已发货状态)在线支付</b> */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_dealOnline_from_Sended() throws com.sh_lianjing.state.StateConvertException {
		if(this != Sended){
			throw new com.sh_lianjing.state.StateConvertException(this, Finished);
		}
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("处理在线支付", this, Finished);
	}

	/** <b>取消(审核不通过状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_cancel_from_VerifyNoPass() throws com.sh_lianjing.state.StateConvertException {
		if(this != VerifyNoPass){
			throw new com.sh_lianjing.state.StateConvertException(this, Canceled);
		}
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("取消", this, Canceled);
	}

	/** <b>终止(待发货状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_terminal_from_Sending() throws com.sh_lianjing.state.StateConvertException {
		if(this != Sending){
			throw new com.sh_lianjing.state.StateConvertException(this, Terminaled);
		}
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("终止", this, Terminaled);
	}

	/** <b>创建</b> */
	public static com.sh_lianjing.state.StateTransition<State_ProductOrder> t_create() {
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("创建", null, Paying);
	}

	/** <b>取消(待付款状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_cancel_from_Paying() throws com.sh_lianjing.state.StateConvertException {
		if(this != Paying){
			throw new com.sh_lianjing.state.StateConvertException(this, Canceled);
		}
		return new com.sh_lianjing.state.StateTransition<State_ProductOrder>("取消", this, Canceled);
	}

	/**
	 * to 转换方法相关
	 */
	public com.sh_lianjing.state.StateTransition<State_ProductOrder> t_cancel_to_Canceled() throws com.sh_lianjing.state.StateConvertException {
		if(this == VerifyNoPass){
			return t_cancel_from_VerifyNoPass();
		}else if(this == Paying){
			return t_cancel_from_Paying();
		}else{
			throw new com.sh_lianjing.state.StateConvertException(this, Canceled);
		}
	}


	/**
	 * 验证方法相关
	 */
	public Validator validator(){
		return new Validator();
	}
	
	public class Validator {
		private com.sh_lianjing.state.validate.StateCondition<State_ProductOrder> condition = new com.sh_lianjing.state.validate.StateCondition<>();
	
		public State_ProductOrder end() throws com.sh_lianjing.state.StateException{
			if(!condition.validate(State_ProductOrder.this)){
				throw new com.sh_lianjing.state.StateException("产品订单状态错误，不能执行操作");
			}
			return State_ProductOrder.this;
		}
	
		/** <b>验证[审核不通过]状态</b> */
		public Validator v_VerifyNoPass() {
			this.condition.add(VerifyNoPass);
			return this;
		}
		/** <b>验证[已发货]状态</b> */
		public Validator v_Sended() {
			this.condition.add(Sended);
			return this;
		}
		/** <b>验证[已终止]状态</b> */
		public Validator v_Terminaled() {
			this.condition.add(Terminaled);
			return this;
		}
		/** <b>验证[待审核]状态</b> */
		public Validator v_Verifing() {
			this.condition.add(Verifing);
			return this;
		}
		/** <b>验证[已取消]状态</b> */
		public Validator v_Canceled() {
			this.condition.add(Canceled);
			return this;
		}
		/** <b>验证[待发货]状态</b> */
		public Validator v_Sending() {
			this.condition.add(Sending);
			return this;
		}
		/** <b>验证[完成]状态</b> */
		public Validator v_Finished() {
			this.condition.add(Finished);
			return this;
		}
		/** <b>验证[待付款]状态</b> */
		public Validator v_Paying() {
			this.condition.add(Paying);
			return this;
		}
	}

}
